package org.springside.examples.showcase.wb.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.RowBounds;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.stereotype.Component;
import org.springside.examples.showcase.wb.entity.WbContent;
import org.springside.modules.orm.Page;

@Component
public class WbContentMyBatisDao extends SqlSessionDaoSupport {

	public List<WbContent> getHotRttWbs() {
		return getSqlSession().selectList("WbContent.getHotRttWbs");
	}

	public Page<WbContent> getByCreatedDate(Page<WbContent> page, String created_date) {
		Map paramMap = new HashMap();
		paramMap.put("created_date", created_date);
		List<WbContent> rowsList = getSqlSession().selectList("WbContent.getByCreatedDate", paramMap, new RowBounds(page.getFirst(), page.getPageSize()));
		page.setResult(rowsList);
		return page;
	}

	public Integer countByCreatedDate(Page<WbContent> page, String created_date) {
		Map paramMap = new HashMap();
		paramMap.put("created_date", created_date);
		Integer rowsCount = getSqlSession().selectOne("WbContent.countByCreatedDate", paramMap);
		return rowsCount;
	}

	public int insertHotRttRelations(WbContent wbContent) {
		return getSqlSession().insert("WbContent.insertHotRttRelations");
	}

	public int updateDocs(String mids, String created_date) {
		Map paramMap = new HashMap();
		paramMap.put("created_date", created_date);
		paramMap.put("mids", mids.split("\\,"));
		return getSqlSession().update("WbContent.updateDocs", paramMap);
	}

}
